<?php include('header.php');?>
<?php


$id = $_GET['id'];

if($_GET['action']=='del'){
	mysql_query("DELETE FROM reservation_detail WHERE reservation_detail_id = '$id' ");
	mysql_query("DELETE FROM reservation_group WHERE reservation_detail_id = '$id' ");
	mysql_query("DELETE FROM reservation_information WHERE reservation_detail_id = '$id' ");
	mysql_query("DELETE FROM reservation WHERE reservation_detail_id = '$id' ");
	
	echo "<script>alert('ลบข้อมูลเรียบร้อยแล้วค่ะ');";
	echo "window.location='room_cancle.php';</script>";
}

	$uQuery = mysql_query("SELECT user_password FROM user WHERE user_id = '".$_SESSION['user_id']."'");
	$uRow = mysql_fetch_array($uQuery);
?>
<script  type="text/javascript">
function ConfirmDel(){
	var PassConfirm=document.getElementById('PassConfirm').value;
	if(PassConfirm==""){
		alert('กรุณาใส่รหัสผ่านผู้เข้าใช้เพื่อยืนยันการยกเลิกด้วยค่ะ');
		focus_text('PassConfirm');
		return false;
	} else {
		if(PassConfirm=='<?php echo $uRow['user_password'];?>'){
			//alert('ลบข้อมูลเรียบร้อยแล้วค่ะ');
			window.location='room_cancle_confirm.php?action=del&id='+<?php echo $id;?>;
			return false;
		} else {
			alert('รหัสผ่านผิด กรุณาใส่ให้ถูกต้องค่ะ!!');
			focus_text('PassConfirm');
			document.getElementById('PassConfirm').value = "";
			return false;
		}
	}
}
</script>
<body onload="focus_text('PassConfirm');">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>ยืนยันยกเลิกการจอง</h1>
    <div class="buttons"><font color="red" size="3">**ใส่รหัสผ่านผู้เข้าใช้เพื่อยืนยันการยกเลิก </font><input type="password" size="10" name="PassConfirm" id="PassConfirm" /> <a onclick="Javascript:if(confirm('ยืนยันการยกเลิก') == true) {ConfirmDel();}else{focus_text('PassConfirm');}" class="button"><span>ยืนยันการยกเลิก</span></a><a onclick="Javascript:window.location='room_cancle.php';" class="button"><span>กลับ</span></a></div>
</div>
<div class="content">
<?php 

	$rQuery = mysql_query("SELECT reservation_detail_id,reservation_detail_fname,reservation_detail_lname FROM reservation_detail WHERE reservation_detail_id='$id'");


?>
<h3><?php if($_POST['Name']!=""){ echo $_POST['Name'];} ?></h3>
<div style="padding: 10px 30px 0px 40px;">
<?php 
while($rRow = mysql_fetch_array($rQuery)){
?>
<h3><?php echo $rRow['reservation_detail_fname']." ".$rRow['reservation_detail_lname'];?><br>รหัสจอง  RE<?php echo sprintf("%08d", $rRow['reservation_detail_id']);?></h3> 
<table class="list2" width="700px">
	<thead>
	<tr>
		<td width="1px" class="center">ลำดับ</td>
		<td width="170px" class="center">วันที่เข้าพัก</td>
		<td class="center">ห้องพักที่จอง</td>
	</tr>
	</thead>
<?php 
	$sQuery = mysql_query("SELECT reservation_checkin FROM reservation WHERE reservation_detail_id = '".$rRow['reservation_detail_id']."' GROUP BY reservation_checkin ORDER BY reservation_checkin");
		$num=0;
	while($sRow = mysql_fetch_array($sQuery)){
		$dQuery = mysql_query("SELECT room.room_name as room_name,room.room_pax as room_pax FROM reservation,room WHERE room.room_id = reservation.room_id AND reservation.reservation_checkin = '".$sRow['reservation_checkin']."' AND reservation.reservation_detail_id = '".$rRow['reservation_detail_id']."' ");
		$roomNum = 0;
		while($dRow = mysql_fetch_array($dQuery)){
			$roomNum++;
			$room_name .= ", ".$dRow['room_name'];
			//$Room_Pax = $Room_Pax + $dRow['room_pax'];
		}
		$num++;
?>
	<tr>
		<td valign="top" class="center"><?php echo $num;?></td>
		<td valign="top" class="right"><?php echo ThaiDate2(strtotime($sRow['reservation_checkin']));?></td>
		<td valign="top" style="padding-left: 20px;" class="left"><?php echo "<b> (".$roomNum." ห้อง)</b> ".substr($room_name, 2);?></td>
	</tr>
<?php 
		$room_name = "";
	} ?>
</table>
<?php } ?>
</div>
</div>
</div>
</body>
<?php include('footer.php');?>
